package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seawaterbt.ssm.config.DataSource;
import com.seawaterbt.ssm.config.DataSourceEnum;
import com.seawaterbt.ssm.entity.*;
import com.seawaterbt.ssm.mapper.ShengBasBuildingMapper;
import com.seawaterbt.ssm.mapper.ShengBasCrewMapper;
import com.seawaterbt.ssm.service.CzBasBuildingService;
import com.seawaterbt.ssm.service.CzBasCommunityService;
import com.seawaterbt.ssm.service.ShengBasBuildingService;
import com.seawaterbt.ssm.service.ShengBasCrewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service

public class ShengBasBulidingServiceImpl extends ServiceImpl<ShengBasBuildingMapper, ShengBas_building> implements ShengBasBuildingService {

    @Autowired
    CzBasBuildingService czBasBuildingService;
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean saveOrUpdate(ShengBas_building entity) {
        return super.saveOrUpdate(entity);
    }

    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean save(ShengBas_building entity) {
        return super.save(entity);
    }

    @DataSource(DataSourceEnum.DB3)
    @Override
    public void toSend() {
        QueryWrapper<BasBuilding> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("code", 130981011).or().likeRight("code", 130903007);
        List<BasBuilding> czlist = czBasBuildingService.list(queryWrapper);
        if (czlist != null){
            for (BasBuilding basBuilding:czlist){
                ShengBas_building shengBas_building = new ShengBas_building();
               shengBas_building.setAddress(basBuilding.getAddress());
               if (!StringUtils.isEmpty(basBuilding.getCodeProvince())){
                   shengBas_building.setBuildingId(basBuilding.getCodeProvince());
                   //往前推
                   //shengBas_building.setCommunityId();
//                   shengBas_building.setCrewId();
                   shengBas_building.setHeatstaionId(basBuilding.getCodeProvince().substring(0,13));
               }
                shengBas_building.setBuildingName(basBuilding.getBuildingName());
                shengBas_building.setBuildingStructure(basBuilding.getBuildingStructure());
                shengBas_building.setBuildingType(basBuilding.getBuildingType());
                shengBas_building.setBuildYear(StringUtils.isEmpty(basBuilding.getBuildYear())?null:Integer.parseInt(basBuilding.getBuildYear()));
                shengBas_building.setEnergyconsumptionType(basBuilding.getEnergyConsumptionType());
                shengBas_building.setEnergySaving(basBuilding.getIsEnergysaving()==0?false:true);
                shengBas_building.setHeatingArea(StringUtils.isEmpty(basBuilding.getHeatingArea())?null:Double.parseDouble(basBuilding.getHeatingArea()));
                shengBas_building.setHeatMeteringDate(basBuilding.getHeatMeteringDate());
                shengBas_building.setIsHeatmeteringTransformed(basBuilding.getIsHeatMeteringTransformed());
                shengBas_building.setAddress(basBuilding.getAddress());
                shengBas_building.setMeasure(basBuilding.getIsMeasure()==0?false:true);
                shengBas_building.setIsWallInsulationtransformed(basBuilding.getIsWallInsulationTransformed());
                shengBas_building.setSeparatecontrol(basBuilding.getIsSeparateControl()==0?false:true);
                shengBas_building.setWallInsulationDate(basBuilding.getWallInsulationDate());
                this.save(shengBas_building);
            }
        }
    }
}
